<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"
	scope="application" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="ThemeBucket">

<title>登录</title>
<link rel="shortcut icon" type="image/x-icon"
	href="${ctxPath}/static/images/lukk.ico" media="screen" />
<link rel="icon" href="${ctxPath}/static/images/lukk.ico"
	type="image/x-icon" />
<link rel="bookmark" href="${ctxPath}/static/images/lukk.ico"
	type="image/x-icon" />
<link href="${ctxPath}/static/css/style.css" rel="stylesheet">
<link href="${ctxPath}/static/css/style-responsive.css" rel="stylesheet">
<script src="${ctxPath}/static/js/html5shiv.js"></script>
<script src="${ctxPath}/static/js/respond.min.js"></script>
<%@ page import="com.lukk.util.RSAUtils"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.security.interfaces.*"%>
<%
	HashMap<String, Object> map = RSAUtils.getKeys();
	//生成公钥和私钥    
	RSAPublicKey publicKey = (RSAPublicKey) map.get("public");
	RSAPrivateKey privateKey = (RSAPrivateKey) map.get("private");
	session.setAttribute("privateKey", privateKey);//私钥保存在session中，用于解密  
	//公钥信息保存在页面，用于加密  
	String publicKeyExponent = publicKey.getPublicExponent().toString(16);
	String publicKeyModulus = publicKey.getModulus().toString(16);
	request.setAttribute("publicKeyExponent", publicKeyExponent);
	request.setAttribute("publicKeyModulus", publicKeyModulus);
%>
</head>

<body class="login-body">
	<div class="container">
		<form id="loginForm" class="form-signin" method="post">
			<div class="form-signin-heading text-center">
				<img src="${ctxPath}/static/images/login-logo.png" alt="" />
			</div>
			<div>
				<c:if test="${login==3}">
					<span style="color: red; position: relative; margin-left: 61px;">长时间无操作,请重新登录!!!!</span>
				</c:if>
			</div>
			<div class="login-wrap">
				<input type="text" class="form-control" value="lukkxulele"
					id="txt_workerCode" placeholder="账号" autofocus> <input
					type="password" class="form-control" id="txt_password"
					value="xulele456987" placeholder="密码"> <input
					class="btn btn-lg btn-login btn-block" type="button"
					onclick="login()" value="登录"> <input
					class="btn btn-lg btn-login btn-block" type="button"
					data-toggle="modal" onclick="javascript:$('#loginForm')[0].reset()"
					value="清空">
			</div>
		</form>
	</div>
	<p align="center">
		备案号：<a href="http://www.miibeian.gov.cn/" target="_blank">豫ICP备17004523号</a>
	</p>
</body>
<script src="${ctxPath}/static/js/jquery-1.10.2.min.js"></script>
<script src="${ctxPath}/static/js/bootstrap.min.js"></script>
<script src="${ctxPath}/static/js/security/security.js"></script>
<script type="text/javascript">
	//登录
	function login() {
		//登录  
		var workerCode = $("#txt_workerCode").val();
		var password = $("#txt_password").val();
		password = password.split("").reverse().join("");
		RSAUtils.setMaxDigits(256);
		var key = new RSAUtils.getKeyPair("${publicKeyExponent}", "",
				"${publicKeyModulus}");
		var encrypedPwd = RSAUtils.encryptedString(key, password);
		
		$.post("${ctxPath}/internalWorker/login", {
			workerCode : workerCode,
			password : encrypedPwd
		}, function(data) {
			if (data == false) {
				fail("账户或者密码错误!");
			} else {
				window.location.href = "${ctxPath}/index.html";
			}
		});
	}
	$(function() {
		//设置回车键出发登录事件
		document.onkeydown = function(event) {
			var e = event || window.event
					|| arguments.callee.caller.arguments[0];
			if (e && e.keyCode == 13) {
				login();
			}
		};
	});
</script>
</html>
